
/*========================================================================================
 *                                                                                      *
 *               Copyright(c) 2013-2014, Cha SangWoo, All rights reserved.              *
 *                                                                                      *
 * This file is part of ChaOS.                                                          *
 *                                                                                      *
 * Permission to use, copy, modify, and distribute this software in source and binary   *
 * forms and its documentation for any purpose and without fee is hereby granted,       *
 * provided that the above copyright notice appear in all copies and that both that     *
 * copyright notice and this permission notice appear in supporting documentation.      *
 *                                                                                      *
 * THIS SOFTWARE IS PROVIDED BY THE CHA SANGWOO AND CONTRIBUTORS "AS IS" AND ANY        *
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED            *
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   *
 * IN NO EVENT SHALL CHA SANGWOO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,    *
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT         *
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,          *
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF            *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE      *
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,                    *
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                   *
 *                                                                                      *
========================================================================================*/

#ifndef __CO_SEMAPHORE_H__
#define __CO_SEMAPHORE_H__

#include "co_types.h"

#ifdef __cplusplus
    extern "C" {
    namespace ChaOS {
#endif

//////////////////////////////////////  < BEGIN >  ///////////////////////////////////////

/*======================================================================================*/
/*!
    @fn             OBJECT co_semaphore_create(UINT16 init_count, UINT16 max_count)

    @brief          Create a semaphore.

    @param [in]     init_count - initial count of semaphore
    @param [in]     max_count  - maximum count of semaphore

    @return         Object for semaphore
*/
/*======================================================================================*/
OBJECT co_semaphore_create(UINT16 init_count, UINT16 max_count);


/*======================================================================================*/
/*!
    @fn             CO_RESULT co_semaphore_take(OBJECT object, UINT16 timeout)

    @brief          Take a semaphore.

    @param [in]     object  -
    @param [in]     timeout -

    @return         CO_RESULT value
*/
/*======================================================================================*/
CO_RESULT co_semaphore_take(OBJECT object, UINT16 timeout);


/*======================================================================================*/
/*!
    @fn             VOID co_semaphore_give(OBJECT object)

    @brief          Give a semaphore.

    @param [in]     - object for semaphre

    @return         None
*/
/*======================================================================================*/
VOID co_semaphore_give(OBJECT object);


/*======================================================================================*/
/*!
    @fn             UINT16 co_semaphore_get_max_count(OBJECT object)

    @brief          Get maximum count of semaphore

    @param [in]     object - object for semaphre

    @return         Maximum count
*/
/*======================================================================================*/
UINT16 co_semaphore_get_max_count(OBJECT object);


/*======================================================================================*/
/*!
    @fn             UINT16 co_semaphore_get_cur_count(OBJECT object)

    @brief          Get count giving.

    @param [in]     object - object for semaphre

    @return         Giving count
*/
/*======================================================================================*/
UINT16 co_semaphore_get_cur_count(OBJECT object);


/*======================================================================================*/
/*!
    @fn             UINT16 co_semaphore_get_remain_count(OBJECT object)

    @brief          Get count giving.

    @param [in]     object - object for semaphre

    @return         
*/
/*======================================================================================*/
UINT16 co_semaphore_get_remain_count(OBJECT object);


/*======================================================================================*/
/*!
    @fn             VOID co_semaphore_reset_count(OBJECT object)

    @brief          

    @param [in]     object - object for semaphre

    @return         None
*/
/*======================================================================================*/
VOID co_semaphore_reset_count(OBJECT object);


/*======================================================================================*/
/*!
    @fn             VOID co_semaphore_add_count(OBJECT object, UINT16 count)

    @brief          

    @param [in]     object - object for semaphre

    @return         None
*/
/*======================================================================================*/
VOID co_semaphore_add_count(OBJECT object, UINT16 count);


/*======================================================================================*/
/*!
    @fn             VOID co_semaphore_sub_count(OBJECT object, UINT16 count)

    @brief          

    @param [in]     object - object for semaphre

    @return         None
*/
/*======================================================================================*/
VOID co_semaphore_sub_count(OBJECT object, UINT16 count);


//////////////////////////////////////  <  END  >  ///////////////////////////////////////

#ifdef __cplusplus
    } /* namespace ChaOS */
    } /* extern "C" */
#endif

#endif //__CO_SEMAPHORE_H__

